<?php
include 'Utils.php';

function db_error() {
	return mysql_error();
}

function db_connect() {
	global $DB_HOST;
	global $DB_USERNAME;
	global $DB_PASSWORD;
	global $DB_SCHEMA;
        $DB_HOST ="locahost";
        
        $DB_USERNAME="root";
        $DB_PASSWORD="";
        $DB_SCHEMA = "tripviet";

	$conn = mysql_connect($DB_HOST, $DB_USERNAME, $DB_PASSWORD);
	if($conn) {
		$db = mysql_select_db($DB_SCHEMA);
		if($db) {
			return $db;
		} else {
			die("Error selecting database: " . htmlspecialchars_default(db_error()));
		}
	} else {
		die("Error connecting to database: " . htmlspecialchars_default(db_error()));
	}
}

function db_execute($stmt) {	
	$ret = mysql_query($stmt);
	if($ret === FALSE) {
		global $dbs_error;
		$dbs_error = mysql_error();
	}
	return $ret;
}

function db_execute_fetch($stmt) {
	$result = db_execute($stmt);
	if($result === FALSE) return FALSE; 
        else return db_fetch($result);
}

function db_free_result($res) {
	mysql_free_result($res);
}

function db_fetch($res) {
	return mysql_fetch_assoc($res);
}

?>
